package DAO.impl;

import model.impl.Station;

import org.hibernate.Query;
import DAO.StationDAO;

/**
 *  Implements StationDAO interface, extend GenericDAOImpl class using as 
 *  parameters entity of Station and Integer class as an ID. It also adds some 
 *  specific to Station entity methods.
 */
public class StationDAOImpl extends GenericDAOImpl<Station, Integer> implements
		StationDAO {

	/**
	 * Looks for station with the instance Station.stationName equals to the
	 * given name parameter.
	 * 
	 * @param name - a String representing the Station.stationName of the required 
	 * 				 station					
	 * @return 	   - Station entity object or null if such object was
	 * 				 not found
	 */
	public Station findStationByName(String name) {
		Station station = null;
		String sqlRequest = "SELECT s FROM Station s WHERE s.stationName = :name";
		Query query = this.getSession().createQuery(sqlRequest)
				.setParameter("name", name);
		station = findOne(query);
		return station;
	}

}
